home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls085.solintel.Z / tls085.solintel / lib / vtcl / tests / input3.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  2.2 KB  |  88 lines

  1. # CVS $Id: input3.tcl,v 1.3 1995/02/03 16:54:54 zibi Exp $
  2. # input3.tcl, 12 Nov 92 
  3. #
  4. # this script demonstrates the VtAddInput and complementary VtRemoveInput
  5. # commands that provide the ability to tell the widget server to 
  6. # monitor activity on a file descriptor, such as a pipe.  This is 
  7. # accomplished by telling wserver the name of the file descriptor to
  8. # watch and the name of the callback function to invoke when there
  9. # is activity.
  10.  
  11. # As used below, the tcl "pipe" command opens the first handle as the
  12. # side of the pipe meant for reading.  The 2nd handle is opened for
  13. # writing.
  14.  
  15. proc InPipeCB {dlog fileId} {
  16.     set data [gets $fileId]
  17.     
  18.     VtInformationDialog $dlog.$fileId   -hidden false \
  19.     -message "Activity on file ID: $fileId\n\n$data"
  20.  
  21. }
  22.  
  23. proc ListWidgetCB {cbs} {
  24.     global selectedData 
  25.  
  26.     set selectedData [keylget cbs selectedItemList]
  27. }
  28.  
  29. proc CancelCB {cbs} {
  30.     set target [keylget cbs widget]
  31.     VtDestroyDialog $target
  32.  
  33.     exit
  34. }
  35.  
  36. proc writeCB {fID cbs} {
  37.     global selectedData outPipe
  38.  
  39.     puts $fID $selectedData
  40.     flush $fID
  41. }
  42.  
  43. # grab name of this script minus the tcl extension
  44. set scriptname [file tail [file root [info script]]]
  45.  
  46. set app [VtOpen $scriptname]
  47.  
  48. pipe p1read p1write
  49. pipe p2read p2write 
  50.  
  51. set dlog [VtFormDialog $app.form1 \
  52.         -MOTIF_verticalSpacing 5 \
  53.         -okLabel "Send Pipe1" -okCallback "writeCB $p1write" \
  54.         -applyLabel "Send Pipe2" -applyCallback "writeCB $p2write"\
  55.          -cancelLabel Exit -cancelCallback CancelCB \
  56.         -defaultButton OK ]
  57.  
  58. VtLabel desc -label \
  59.      "Demo of VtAddInput and VtRemoveInput commands" \
  60.      -leftSide FORM -rightSide FORM \
  61.  
  62.  
  63. VtSeparator sep -leftSide FORM -rightSide FORM  -horizontal
  64.  
  65. set data [list "Short"  \
  66.                "Medium Test line"  \
  67.                "Long test line that is sent to input pipe"  \
  68.                "VtAddInput is used every time a line is selected"]
  69.  
  70. set lst [VtList listwidget \
  71.        -itemList $data \
  72.        -leftSide FORM -rightSide FORM -bottomSide FORM \
  73.        -scrollBar  1\
  74.        -rows 3 -callback ListWidgetCB]
  75.  
  76. global selectedData 
  77.  
  78. VtListSelectItem $lst -item Short
  79. set selectedData Short
  80.  
  81.  
  82. VtAddInput $p1read "InPipeCB $dlog"
  83. VtAddInput $p2read "InPipeCB $dlog"
  84.  
  85. VtShowDialog $dlog
  86.  
  87. VtMainLoop
  88.